#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
const LL mod=1e9+7;
LL dp[maxn];
LL sum[maxn];
int main(void)
{
  ///cin.tie(0);std::ios::sync_with_stdio(false);
  LL t,k;cin>>t>>k;
  for(LL i=1;i<=k-1;i++){
        dp[i]=1;
  }
  dp[k]=2;
  for(LL i=k+1;i<=1e5;i++){
        dp[i]=(dp[i-k]%mod+dp[i-1]%mod)%mod;
  }
  for(LL i=1;i<=1e5;i++){
    sum[i]=(sum[i-1]%mod+dp[i]%mod)%mod;
  }
  while(t--){
    LL l,r;cin>>l>>r;
    cout<<(sum[r]%mod-sum[l-1]%mod+mod)%mod<<endl;
  }
return 0;
}
